package com.stuManSystem.base;

import com.stuManSystem.config.Dao;
import com.stuManSystem.dao.AdminDao;
import com.stuManSystem.dao.StudentDao;
import com.stuManSystem.util.DBUtil;

import java.sql.ResultSet;

public class BaseDao {

    protected final DBUtil db = DBUtil.getDBUtil();
    protected ResultSet rs;
    private static BaseDao baseDAO;

    //同步锁,,,关键字：synchronized：锁的概念
    public static synchronized BaseDao getAbilityDAO(Dao dao) {
        switch (dao) {

            case AdminDao:
                if (baseDAO == null || baseDAO.getClass() != AdminDao.class) {
                    baseDAO = AdminDao.getInstance();
                }
                break;
            case StudentDao:
                if (baseDAO == null || baseDAO.getClass() != StudentDao.class) {
                    baseDAO = StudentDao.getInstance();
                }
                break;
            default:
                break;
        }
        return baseDAO;
    }


}
